app.controller('bpmTaskListController', ['$scope', 'httpWrapService', '$state', '$stateParams','uiGridConstants','GridFactory','dialogs',
        function($scope, httpWrapService, $state, $stateParams,uiGridConstants, GridFactory,dialogs) {

    $scope.page = {
        pageSize : 10,
        currentPage : 1
    }

    $scope.load = function(){
        httpWrapService.post('bpm/task/list.do',{
            externalParams : {
                pageSize : $scope.page.pageSize,
                pageNumber : $scope.page.currentPage
            }
        }).then(function (res) {
            $scope.list = res.data.page.rows;
            $scope.page = res.data.page;

            $scope.map = res.data.map;
            $scope.$watch('list', function(){
                $('.footable').trigger('footable_redraw');
            });
        });
    }
    $scope.load();

    $scope.$watch('page.currentPage', function(){
        $scope.load();
    });



    /**
     * 签收
     */
    $scope.claim = function(taskId){
        httpWrapService.post('bpm/task/claim/' + taskId + '.do',{
        }).then(function (res) {
        	$scope.load();
            dialogs.notify('提示', res.data.msg, {size: 'md'});
        }, function(res) {
            dialogs.error('错误', res.data.msg, {size: 'md'});
        });
    }
    /**
     * 反签收
     * @param taskId
     */
    $scope.unclaim = function(taskId){
        httpWrapService.post('bpm/task/unclaim/' + taskId + '.do',{
        }).then(function (res) {
            $scope.load();
            dialogs.notify('提示', res.data.msg, {size: 'md'});
        }, function(res) {
            dialogs.error('错误', res.data.msg, {size: 'md'});
        });
    }
}]);